<?php
	session_start();
	if (empty($_SESSION['usuario'])){
		session_destroy();
		header("Location:principal.php");
	}
	else{
		$tipo=$_GET["id_tipo"];
		$usuario=$_GET["id_usuario"];
	}
?>
<html>
	<head>
		<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
		<title>Modificaci&oacute;n de datos de libros</title>
	</head>
	<body>
		<div class="titulo">Modificaci&oacute;n de datos de libros</div>
		<div class="menu">
			<?php
				include ("menu.php");
				if (empty($_SESSION['usuario'])){
					nomenu();
				}
				else{
					menu($tipo,$usuario);
				}
			?>
		</div>
		<div class="contenido">
			<div class="cerrarsesion">
				<?php echo $usuario;?> | <a href="principal.php">Cerrar Sesi&oacute;n</a>		
			</div>
			<marquee><h1 align=\"center\">LIBRER&Iacute;A VIRTUAL </h1></marquee>
			<?php
				include("conexion.php");
				$autor=$_POST["autor"];
				$titulo=$_POST["titulo"];
				$consulta="SELECT * FROM libros WHERE (autor=\"$autor\" and titulo=\"$titulo\");";
				$resultado=mysql_query($consulta,$conexion);
				$verificar=mysql_fetch_array($resultado);
				$id=$verificar["ID"];
				$isbn=$verificar["isbn"];
				$editorial=$verificar["editorial"];
				$ano=$verificar["ano"];
				$genero=$verificar["genero"];
				$foto=$verificar["foto"];
				$nombresinopsis=$verificar["nombresinopsis"];
				$sinopsis=$verificar["sinopsis"];
				$precio=$verificar["precio"];
				if (!$verificar){
					echo "<h3 align=center>LIBRO no existe.</h3>";
					exit();
				}
				echo "<FORM onSubmit=\"return validar()\" ACTION=\"datos_modificar2.php?id_tipo=$tipo&id_usuario=$usuario&id=$id\" method=\"post\">";
					echo "<fieldset>";
						echo "<legend>Introduzca el nuevo libro</legend>";
						echo "<table border=\"1\" cellspacing=\"5\" cellpadding=\"3\">";
							echo "<tr>";
								echo "<td>";
									echo "<label align=\"left\">Autor: <input name=\"autor\" type=\"text\" value=\"$autor\" maxlength=\"30\"></label>";
								echo "</td>";
								echo "<td>";
									echo "<label align=\"left\">T&iacute;tulo: <input name=\"titulo\" type=\"text\" value=\"$titulo\" maxlength=\"30\"></label>";
								echo "</td>";
								echo "<td>";
									echo "<label align=\"left\">I.S.B.N.: <input name=\"isbn\" type=\"text\" value=\"$isbn\" maxlength=\"17\"></label>";
								echo "</td>";
								echo "<td>";
									echo "<h3 align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"A&ntilde;adir\"/></h3>";
								echo "</td>";
							echo "</tr>";
							echo "<tr>";
								echo "<td>";
									echo "<label align=\"left\">Editorial: <input type=\"text\" name=\"editorial\" value=\"$editorial\" maxlength=\"20\"></label>";
								echo "</td>";
								echo "<td>";
									echo "<label align=\"left\">A&#241o de edici&oacute;n: <input type=\"number\" name=\"ano\" value=\"$ano\" maxlength=\"4\"></label>";
								echo "</td>";
								echo "<td>";
									echo "<label align=\"left\">G&eacute;nero: <input type=\"text\" name=\"genero\" value=\"$genero\" maxlength=\"20\"></label>";
								echo "</td>";
								echo "<td>";
									echo "<label align=\"left\">Precio: <input type=\"number\" name=\"precio\" value=\"$precio\" maxlength=\"3,2\"></label>";
								echo "</td>";
							echo "</tr>";
							echo "<tr>";
								echo "<td colspan=\"3\" align=\"left\">";
									echo "<label>Foto portada: <input type=\"file\" name=\"fotoportada\" value=\"$foto\"></label>";
								echo "</td>";
								echo "<td>";
									echo "<label align=\"left\">Nombre datos principales: <input type=\"text\" name=\"datosprincipales\" value=\"$sinopsis\" maxlength=\"20\"></label>";
								echo "</td>";
							echo "</tr>";
							echo "<tr>";
								echo "<td colspan=\"4\" align=\"left\">";
									echo "<label valign=\"top\">Sinopsis: <textarea name=\"sinopsis\" cols=\"95\" rows=\"5\" value=\"$sinopsis\" maxlength=\"1000\"></textarea></label>";
								echo "</td>";
							echo "</tr>";
						echo "</table>";
					echo "</fieldset>";
				echo "</FORM>";
				mysql_close($conexion);	
				echo "<br><br><br>";
			?>
		</div>
		<div class="pie">Carlos Guerrero Rodr&iacute;guez &#169;</div>
	</body>
</html>